﻿
Partial Class WebForm_ManageMOICodeMapping_SearchMOICodemapping
    Inherits System.Web.UI.UserControl

    Protected Sub btGetData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btGetData.Click
        Me.BindGV()
    End Sub

    Private Sub BindGV()

        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0

        sql.AppendFormat("Select ch.TableText,ci.ColumnText,cm.*  ")
        sql.AppendFormat(" From CodeMapping cm Left Join CodeItem ci ON cm.TableName = ci.TableName And cm.ColumnName = ci.ColumnName ")
        sql.AppendFormat(" Left Join CodeHeader ch ON ch.CodeHeaderID = cm.TableName ")
        sql.AppendFormat(" Where cm.MOIValue is not null And cm.MOIValue <> '' ")
        sql.AppendFormat(" And cm.TableName = '{0}' ", Me.ddlTableName.SelectedValue)
        sql.AppendFormat(" And cm.ColumnName = '{0}' ", Me.ddlColumnName.SelectedValue)

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Editing" Then
            Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

            Me.TableName = key("TableName")
            Me.ColumnName = key("ColumnName")
            Me.CodeMappingValue = key("Value")
        End If

    End Sub

    Public Property TableName() As String
        Get
            Return ViewState("TableName")
        End Get
        Set(ByVal value As String)
            ViewState("TableName") = value
        End Set
    End Property

    Public Property ColumnName() As String
        Get
            Return ViewState("ColumnName")
        End Get
        Set(ByVal value As String)
            ViewState("ColumnName") = value
        End Set
    End Property

    Public Property CodeMappingValue() As String
        Get
            Return ViewState("CodeMappingValue")
        End Get
        Set(ByVal value As String)
            ViewState("CodeMappingValue") = value
        End Set
    End Property
End Class
